package com.yuncheng.spcyApi.flowController;

import com.yuncheng.spcyApi.vo.flow.SpcyJobXqVo;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.spcyApi.constant.common.BusinessConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.SpcySqsxBasic;
import com.yuncheng.spcyApi.entity.SpcySqsxJob;
import com.yuncheng.spcyApi.entity.SpcySqsxXpjl;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.flow.FlowVo;
import com.yuncheng.spcyApi.flow.JcyRckpFlowService;
import com.yuncheng.spcyApi.flow.JcyRckpHpFlowService;
import com.yuncheng.spcyApi.flow.SpcyFlowConstant;

import com.yuncheng.spcyApi.mapper.SpcyFlowMapper;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import com.yuncheng.spcyApi.service.ISpcySqsxBaiscService;
import com.yuncheng.spcyApi.service.ISpcySqsxJobService;
import com.yuncheng.spcyApi.service.ISpcySqsxXpjlService;
import com.yuncheng.spcyApi.utils.*;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.common.Result;
import com.yuncheng.spcyApi.vo.spcy.SpcyFlowVo;
import com.yuncheng.spcyApi.vo.spcy.SpcyReturnVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import utils.LogUtils;
import utils.ObjectToMapUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URLEncoder;
import java.util.*;

@Api(tags = "审评查验-日常考评流程接口")
@RestController
@RequestMapping("/api/spzx-spcy/flow-rckp")
public class JcyRckpFlowController extends BaseController<SpcySqsxBasic, ISpcySqsxBaiscService> {
    private static final Logger log = LoggerFactory.getLogger(SpcyFlowYpscController.class);

    /*@Resource
    private RckpFlowService rckpFlowService;

    @Resource
    private RckpConstant rckpConstant;*/

    @Resource
    private SpcyFlowMapper spcyFlowMapper;

    @Resource
    private ISpcySqsxBaiscService spcySqsxBaiscService;

    /*@Resource
    private BusService busService;*/

    @Resource
    private ISpcySqsxJobService spcySqsxJobService;

    @Resource
    private ISpcyLogService spcyLogService;

    @Resource
    private ISpcySqsxXpjlService spcySqsxXpjlService;

    @Resource
    private MyExcelUtils myExcelUtils;

    @Resource
    private JcyRckpFlowService jcyRckpFlowService;

    @Resource
    @Lazy
    private JcyRckpHpFlowService jcyRckpHpFlowService;

    @Log(title = "日常考评-流程监控-分页查询")
    @ApiOperation(value = "日常考评-流程监控-分页查询")
    @GetMapping("flowJkPage")
    public HttpResult<?> flowJkPage(SpcyFlowVo flowVo, PageVo pageVo, OrderItemVo orderItemVo,
                                    @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }

        flowVo.setFblzt(SpcyConstant.BLZT_DB);
        flowVo.setFlcmc(SpcyFlowConstant.RCKP_LCMC);
        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        Page<SpcyFlowVo> list = spcyFlowMapper.flowJobPage(page, onlyCurrentUser, user, flowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "日常考评-流程列表-分页查询")
    @ApiOperation(value = "日常考评-流程列表-分页查询")
    @GetMapping("flowJobPage")
    public HttpResult<?> flowJobPage(SpcyFlowVo flowVo, PageVo pageVo, OrderItemVo orderItemVo,
                                     @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }

        flowVo.setFblzt(SpcyConstant.BLZT_DB);
        flowVo.setFlcmc(SpcyFlowConstant.RCKP_LCMC);
        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(),pageVo.getPageSize());
        Page<SpcyFlowVo> list = spcyFlowMapper.flowJobPage(page, onlyCurrentUser, user, flowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "APP日常考评-流程列表-分页查询")
    @ApiOperation(value = "APP日常考评-流程列表-分页查询")
    @GetMapping("flowAppJobPage")
    public HttpResult<?> flowAppJobPage(SpcyFlowVo flowVo, PageVo pageVo, OrderItemVo orderItemVo){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }

        flowVo.setFblzt(SpcyConstant.BLZT_DB);
        flowVo.setFlcmc(SpcyFlowConstant.RCKPHP_LCMC);
        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(),pageVo.getPageSize());
        Page<SpcyFlowVo> list = spcyFlowMapper.flowJobPage(page, true, user, flowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "日常考评-我的已办流程列表-分页查询")
    @ApiOperation(value = "日常考评-我的已办流程列表-分页查询")
    @GetMapping("flowMyYbJobPage")
    public HttpResult<?> flowMyYbJobPage(SpcyFlowVo flowVo, PageVo pageVo, OrderItemVo orderItemVo){

        String userid = GetCurrentUserUtils.getCurrentUserId();
        flowVo.setFblzt(SpcyConstant.BLZT_YB);

//        String currentUserOrgId = GetCurrentUserUtils.getCurrentUserOrgId();
        /*if (currentUserOrgId.equals(SpcyConstant.HCY_ORGID)){
            flowVo.setFlcmc(SpcyFlowConstant.RCKPHP_LCMC);
        }else {
            flowVo.setFlcmc(SpcyFlowConstant.RCKP_LCMC2);
        }*/
        flowVo.setFlcmc(SpcyFlowConstant.RCKP_LCMC);

        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        Page<SpcyFlowVo> list = spcyFlowMapper.selectYbRckpFlowJobPage(page, userid, flowVo, orderItemVo);

        /*if (CollectionUtil.isNotEmpty(list.getRecords())){
            list.setRecords(list.getRecords().stream().collect(Collectors.collectingAndThen(
                    Collectors.toCollection(
                            () -> new TreeSet<>(
                                    Comparator.comparing(o -> o.getSqsxid())
                            )
                    ), ArrayList<SpcyFlowVo>::new
            )));
        }*/
        return HttpResult.ok(list);
    }

    @Log(title = "日常考评查询")
    @ApiOperation(value = "日常考评查询")
    @GetMapping("rckpcxPageList")
    public HttpResult<?> rckpcxPageList(SpcyFlowVo flowVo, PageVo pageVo, OrderItemVo orderItemVo){

//        flowVo.setFlcmc(SpcyFlowConstant.RCKP_LCMC2);
        flowVo.setFlcmc(SpcyFlowConstant.RCKP_LCMC);
        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        Page<SpcyFlowVo> list = spcyFlowMapper.selectRckpCxPageList(page, null, flowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "日常考评流程-保存接口")
    @ApiOperation(value = "日常考评流程-保存接口")
    @PostMapping(value = "/saveFlow")
    public HttpResult<?> saveFlow(@RequestBody FlowVo flowVo) {
        if (StringUtils.isBlank(flowVo.getJobid())){
            throw new BusinessException("流程参数为空！");
        }

        SpcySqsxJob nowJob = spcySqsxJobService.getById(flowVo.getJobid());
        if (nowJob == null){
            throw new BusinessException("没有相匹配的流程！");
        }

        if (StringUtils.isNotBlank(nowJob.getFlcmc()) && nowJob.getFlcmc().contains(SpcyFlowConstant.RCKPHP_LCMC)){
            Result result = jcyRckpHpFlowService.handleFlow(flowVo, flowVo.getJobid(), nowJob, null, SpcyFlowConstant.SUBMIT_TYPE_SAVE, flowVo.getOpinion());
            if (!result.isSuccess()){
                throw new BusinessException(result.getMessage());
            }
        }else {
            Result httpResult = jcyRckpFlowService.handleFlow(flowVo, flowVo.getJobid(), nowJob, null, SpcyFlowConstant.SUBMIT_TYPE_SAVE, flowVo.getOpinion());
            if (!httpResult.isSuccess()) {
                throw new BusinessException(httpResult.getMessage());
            }
        }

        return HttpResult.ok("保存成功");
    }

    @Log(title = "日常考评流程-提交接口")
    @ApiOperation(value = "日常考评流程-提交接口")
    @PostMapping(value = "/submitFlow")
    public HttpResult<?> submitFlow(@RequestBody FlowVo flowVo) {
        if (StringUtils.isBlank(flowVo.getJobid())){
            throw new BusinessException("流程参数为空！");
        }

        SpcySqsxJob nowJob = spcySqsxJobService.getById(flowVo.getJobid());
        if (nowJob == null){
            throw new BusinessException("没有相匹配的流程！");
        }

        if (StringUtils.isNotBlank(nowJob.getFlcmc()) && nowJob.getFlcmc().contains(SpcyFlowConstant.RCKPHP_LCMC)){
            Result result = jcyRckpHpFlowService.handleFlow(flowVo, flowVo.getJobid(), nowJob, null, SpcyFlowConstant.SUBMIT_TYPE_SUBMIT, flowVo.getOpinion());
            if (!result.isSuccess()){
                throw new BusinessException(result.getMessage());
            }
        }else {
            Result httpResult = jcyRckpFlowService.handleFlow(flowVo, flowVo.getJobid(), nowJob,null, SpcyFlowConstant.SUBMIT_TYPE_SUBMIT, flowVo.getOpinion());
            if (!httpResult.isSuccess()) {
                throw new BusinessException(httpResult.getMessage());
            }
        }

        return HttpResult.ok("提交成功");
    }

    @Log(title = "退回上一环节流程任务")
    @ApiOperation(value = "退回上一环节流程任务")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobid",value = "流程任务id",required = true),
            @ApiImplicitParam(name = "opinion",value = "意见",required = true)
    })
    @PostMapping(value = "returnUpperFlowJob")
    public HttpResult<?> returnUpperFlowJob(@RequestBody SpcyReturnVo spcyReturnVo){
        jcyRckpFlowService.getReturnUpperFlowJob(spcyReturnVo);

        return HttpResult.ok("退回成功");
    }

    @Log(title = "日常考评-查询当前流程任务详情-通过当前流程任务id")
    @ApiOperation(value = "日常考评-查询当前流程任务详情-通过当前流程任务id")
    @GetMapping(value = "queryJobByJobId")
    public HttpResult<?> queryJobByJobId(@RequestParam(value = "jobid",defaultValue = "")String jobid){
        if (StringUtils.isBlank(jobid)){
            return HttpResult.error("流程参数为空！");
        }

        SpcySqsxJob nowJob = spcySqsxJobService.getById(jobid);
        if (nowJob == null){
            return HttpResult.error("没有相匹配的流程任务数据！");
        }

        if (StringUtils.isNotBlank(nowJob.getFlcmc()) && nowJob.getFlcmc().contains(SpcyFlowConstant.RCKPHP_LCMC)){

            return HttpResult.ok(jcyRckpHpFlowService.getJobConcernByJobId(jobid));
        }else {

            return HttpResult.ok(jcyRckpFlowService.getJobConcernByJobId(jobid));
        }
    }

    @Log(title = "获取APP-日常考评-查询当前流程任务详情")
    @ApiOperation(value = "获取APP-日常考评-查询当前流程任务详情")
    @GetMapping(value = "queryAppJobInfo")
    public HttpResult queryAppJobInfo(@RequestParam(value = "jobid",defaultValue = "")String jobid){
        if (StringUtils.isBlank(jobid)){
            return HttpResult.error("流程参数为空！");
        }

        SpcyJobXqVo nowJob = spcySqsxJobService.selectJobInfoById(jobid);
        if (nowJob == null){
            return HttpResult.error("没有相匹配的流程任务数据！");
        }

        if (StringUtils.isNotBlank(nowJob.getFlcmc()) && nowJob.getFlcmc().contains(SpcyFlowConstant.RCKPHP_LCMC)){

            return HttpResult.ok(jcyRckpHpFlowService.getAppJobConcernByJobId(jobid, nowJob));
        }else {

            return HttpResult.ok(jcyRckpFlowService.getAppJobConcernByJobId(jobid, nowJob));
        }
    }

    @GetMapping("initRckpHpFlow")
    public HttpResult initRckpHpFlow(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        jcyRckpHpFlowService.initRckpHpFlow(sqsxid);
        return HttpResult.ok();
    }

    @Log(title = "检查员互评一键优秀")
    @ApiOperation(value = "检查员互评一键优秀")
    @GetMapping("jcyhpYjyx")
    public HttpResult jcyhpYjyx(@RequestParam(value = "id",defaultValue = "")String id){

        jcyRckpHpFlowService.jcyhpYjyx(id, GetCurrentUserUtils.getCurrentUserId());

        return HttpResult.ok("操作成功");
    }

    @Log(title = "检查员互评一键清空")
    @ApiOperation(value = "检查员互评一键清空")
    @GetMapping("jcyhpYjQk")
    public HttpResult jcyhpYjQk(@RequestParam(value = "id",defaultValue = "")String id){

        jcyRckpHpFlowService.jcyhpYjQk(id, GetCurrentUserUtils.getCurrentUserId());

        return HttpResult.ok("操作成功");
    }

    @Log(title = "检查员互评-评价更新")
    @ApiOperation(value = "检查员互评-评价更新")
    @PutMapping("updateJcyhpPj")
    public HttpResult updateJcyhpPj(@RequestBody HashMap<String,String> buffer){

        jcyRckpHpFlowService.updateJcyhpPj(buffer);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "查询评价人的检查员互评记录")
    @ApiOperation(value = "查询评价人的检查员互评记录")
    @GetMapping("queryPjrJcyHpjlList")
    public HttpResult queryPjrJcyHpjlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        return HttpResult.ok(jcyRckpHpFlowService.queryPjrJcyHpjlList(sqsxid, GetCurrentUserUtils.getCurrentUserId()));
    }

    @Log(title = "查询所有的检查员互评记录")
    @ApiOperation(value = "查询所有的检查员互评记录")
    @GetMapping("queryAllJcyHpjlList")
    public HttpResult queryAllJcyHpjlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){


        return HttpResult.ok(jcyRckpHpFlowService.queryAllJcyHpjlListNew(sqsxid));
    }

    @Log(title = "日常考评统计-分页查询")
    @ApiOperation(value = "日常考评统计-分页查询")
    @GetMapping(value = "queryRckpStatPageList")
    public HttpResult<?> queryRckpStatPageList(SpcySqsxBasic sqsx, PageVo pageVo, OrderItemVo orderItemVo){

        Page<SpcySqsxBasic> page = new Page<>(pageVo.getPageNo(),pageVo.getPageSize());
        LambdaQueryWrapper<SpcySqsxBasic> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(sqsx.getFywflcode()),SpcySqsxBasic::getFywflcode,sqsx.getFywflcode());
        queryWrapper.like(StringUtils.isNotBlank(sqsx.getFsxmc()),SpcySqsxBasic::getFsxmc,sqsx.getFsxmc());
        queryWrapper.like(StringUtils.isNotBlank(sqsx.getFqymc()),SpcySqsxBasic::getFqymc,sqsx.getFqymc());
        queryWrapper.like(StringUtils.isNotBlank(sqsx.getFszdq()),SpcySqsxBasic::getFsxmc,sqsx.getFszdq());
        queryWrapper.like(StringUtils.isNotBlank(sqsx.getFslbh()),SpcySqsxBasic::getFslbh,sqsx.getFslbh());
        queryWrapper.like(StringUtils.isNotBlank(sqsx.getFrckpjg()),SpcySqsxBasic::getFrckpjg,sqsx.getFrckpjg());
        queryWrapper.isNotNull(SpcySqsxBasic::getFrckpsj);

        if (StringUtils.isNotBlank(orderItemVo.getOrderItem())){
            OrderItemUtils.setOrderItem(queryWrapper, orderItemVo);
        }

        Page<SpcySqsxBasic> pageList = spcySqsxBaiscService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }

    @Log(title = "查看日常考评-统计页面详情")
    @ApiOperation(value = "查看日常考评-统计页面详情")
    @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true)
    @GetMapping(value = "queryRckpStatJbxx")
    public HttpResult<?> queryRckpStatJbxx(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项id不能为空");
        }

        LambdaQueryWrapper<SpcySqsxJob> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SpcySqsxJob::getFpid, sqsxid);
        queryWrapper.eq(SpcySqsxJob::getFhjmc, SpcyFlowConstant.RCKP_HJMC_END);
        queryWrapper.eq(SpcySqsxJob::getFlcmc, SpcyFlowConstant.RCKP_LCMC);
        List<SpcySqsxJob> jobList = spcySqsxJobService.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(jobList)){
            String jobid = jobList.get(0).getId();

            Map map = jcyRckpFlowService.getJobConcernByJobId(jobid);
            return HttpResult.ok(map);
        }else {
            return HttpResult.error("当前数据没有完成考评，无法查看。");
        }
    }

    /*@Log(title = "初始化-日常考评流程")
    @ApiOperation(value = "初始化-日常考评流程")
    @GetMapping(value = "initRckpFlow")*/
    public HttpResult<?> initRckpFlow(@RequestParam("sqsxid")String sqsxid){
        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        if (currentUser == null){
            return HttpResult.error("登录已过期，请重新登录");
        }

        Result result = jcyRckpFlowService.initJob(sqsxid, currentUser);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("初始化成功");
    }


    @Log(title = "批量查询日常考评流程任务详情")
    @ApiOperation(value = "批量查询日常考评流程任务详情")
    @ApiImplicitParam(name = "jobids", value = "流程任务id,jobid参数逗号拼接",required = true)
    @GetMapping(value = "queryBatchJobByJobIds")
    public HttpResult<?> queryBatchJobByJobIds(@RequestParam(value = "jobids",defaultValue = "")String jobids) {
        if (StringUtils.isBlank(jobids)) {
            return HttpResult.error("参数不能为空,请选择数据");
        }
        List<Map> mapList = new ArrayList<>();
        List<String> jobidsList = StringPatternUtils.getListByIds(jobids);
        if (CollectionUtils.isNotEmpty(jobidsList)) {
            for (String jobid : jobidsList){
                mapList.add(jcyRckpFlowService.getRckpxxByJobId(jobid));
            }
        }

        return HttpResult.ok(mapList);
    }

    @Log(title = "对选派人员评价")
    @ApiOperation(value = "对选派人员评价")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "选派记录id",required = true),
            @ApiImplicitParam(name = "fljzlqk",value = "廉洁自律情况",required = false),
            @ApiImplicitParam(name = "fzdjcqd",value = "制定检查清单",required = false),
            @ApiImplicitParam(name = "fhdqxqk",value = "核对缺陷情况",required = false),
            @ApiImplicitParam(name = "fxcjcqxfj",value = "现场检查缺陷分级",required = false),
            @ApiImplicitParam(name = "fxcjczy",value = "现场检查作业",required = false),
            @ApiImplicitParam(name = "fzhpj",value = "综合评价",required = false),
            @ApiImplicitParam(name = "fbz",value = "备注",required = false)
    })
    @PutMapping(value = "xpHcyPj")
    public HttpResult<?> xpHcyPj(@RequestBody HashMap<String,String> buffer){
        String id = buffer.get("id");
        if (StringUtils.isBlank(id)){
            return HttpResult.error("id参数不能为空");
        }
        SpcySqsxXpjl xpjlUpdate = spcySqsxXpjlService.getById(id);
        if (xpjlUpdate == null){
            return HttpResult.error("当前选派人员记录不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(xpjlUpdate);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        try {
            BeanUtils.populate(xpjlUpdate, buffer);
        } catch (IllegalAccessException e) {
            log.error("修改申请检查项目出错-【IllegalAccessException】- {}",e.getMessage());
        } catch (InvocationTargetException e) {
            log.error("修改申请检查项目出错-【InvocationTargetException】",e.getMessage());
        }
        spcySqsxXpjlService.updateById(xpjlUpdate);

        String nowNodeName = "日常考评"; // 当前环节名称
        String operContent = "基本信息修改：";
        operContent += LogUtils.BeanModifyMsg(xpjlUpdate,oldMap);
        spcyLogService.addLogs(nowNodeName,operContent,xpjlUpdate.getFsqsxid(), "对选派人员评价", SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("评价成功");
    }

    @Log(title = "选派人员评价-一键优秀")
    @ApiOperation(value = "选派人员评价-一键优秀")
    @ApiImplicitParam(name = "id",value = "选派记录id",required = true)
    @GetMapping(value = "xpHcyPjToOneExcellent")
    public HttpResult<?> xpHcyPjToOneExcellent(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("id参数不能为空");
        }
        SpcySqsxXpjl xpjlUpdate = spcySqsxXpjlService.getById(id);
        if (xpjlUpdate == null){
            return HttpResult.error("当前选派人员记录不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(xpjlUpdate);
        xpjlUpdate.setFljzlqk(SpcyConstant.XPJl_PJ_YX);
        xpjlUpdate.setFzdjcqd(SpcyConstant.XPJl_PJ_YX);
        xpjlUpdate.setFhdqxqk(SpcyConstant.XPJl_PJ_YX);
        xpjlUpdate.setFxcjcqxfj(SpcyConstant.XPJl_PJ_YX);
        xpjlUpdate.setFxcjczy(SpcyConstant.XPJl_PJ_YX);
        xpjlUpdate.setFzhpj(SpcyConstant.XPJl_PJ_YX);
        spcySqsxXpjlService.updateById(xpjlUpdate);

        String nowNodeName = "日常考评"; // 当前环节名称
        String operContent = "基本信息修改：";
        operContent += LogUtils.BeanModifyMsg(xpjlUpdate,oldMap);
        spcyLogService.addLogs(nowNodeName,operContent,xpjlUpdate.getFsqsxid(), "选派人员评价-一键优秀", SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("评价成功");
    }

    @Log(title = "选派人员评价-一键清空评价")
    @ApiOperation(value = "选派人员评价-一键清空评价")
    @ApiImplicitParam(name = "id",value = "选派记录id",required = true)
    @GetMapping(value = "xpHcyPjToEmpty")
    public HttpResult<?> xpHcyPjOneExcellent(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("id参数不能为空");
        }
        SpcySqsxXpjl xpjlUpdate = spcySqsxXpjlService.getById(id);
        if (xpjlUpdate == null){
            return HttpResult.error("当前选派人员记录不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(xpjlUpdate);
        xpjlUpdate.setFljzlqk("");
        xpjlUpdate.setFzdjcqd("");
        xpjlUpdate.setFhdqxqk("");
        xpjlUpdate.setFxcjcqxfj("");
        xpjlUpdate.setFxcjczy("");
        xpjlUpdate.setFzhpj("");
        spcySqsxXpjlService.updateById(xpjlUpdate);

        String nowNodeName = "日常考评"; // 当前环节名称
        String operContent = "基本信息修改：";
        operContent += LogUtils.BeanModifyMsg(xpjlUpdate,oldMap);
        spcyLogService.addLogs(nowNodeName,operContent,xpjlUpdate.getFsqsxid(), "选派人员评价-一键清空评价", SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("评价成功");
    }

    @Log(title = "刷新选派人员评价")
    @ApiOperation(value = "刷新选派人员评价")
    @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true)
    @GetMapping(value = "queryXpHcy")
    public HttpResult<?> queryXpHcy(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项id不能为空");
        }
        // 申请事项的选派记录-查验
        Map map = new HashMap();
        List<SpcySqsxXpjl> cyxpjlList = spcySqsxXpjlService.getTyXpXpjlZsjcyList(sqsxid);

        map.put("cyxpjlList", cyxpjlList); // 申请事项-选派记录-查验
        return HttpResult.ok(map);
    }

    @Log(title = "导出日常考评基本信息数据-表格excel")
    @ApiOperation(value = "导出日常考评基本信息数据-表格excel")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "ids",value = "申请事项id字符逗号分割",required = true),
            @ApiImplicitParam(name = "fsxmc",value = "事项名称",required = true),
            @ApiImplicitParam(name = "fjclx",value = "检查类型",required = true),
            @ApiImplicitParam(name = "frckpjg",value = "日常考评结果",required = true),
            @ApiImplicitParam(name = "fslbh",value = "受理编号",required = true)
    })
    @GetMapping("/exportRckpJbxxData")
    public void exportRckpJbxxData(@RequestParam(value = "ids",defaultValue = "")String ids,
                                   SpcySqsxBasic sqsx,
                                   OrderItemVo orderItemVo,
                                   HttpServletResponse response){
        try {
            String name = "exportRckpJbxxData";
            response.setContentType("application/ms-excel;charset=UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename="
                    .concat(String.valueOf(URLEncoder.encode(name+".xls", "UTF-8"))));
            OutputStream out = response.getOutputStream();

            List<String> IdsList = Arrays.asList(ids.split(","));
            List<Object> list = new ArrayList<>(); // 导出的数据
            // 多选导出
            if (StringUtils.isNotEmpty(ids)) {
                List<SpcySqsxBasic> sqsxBasicList = spcySqsxBaiscService.listByIds(IdsList);
                if (CollectionUtils.isNotEmpty(sqsxBasicList)){
                    for (SpcySqsxBasic e : sqsxBasicList){
                        list.add(e);
                    }
                }
            }else {
                LambdaQueryWrapper<SpcySqsxBasic> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.like(StringUtils.isNotBlank(sqsx.getFywflcode()),SpcySqsxBasic::getFywflcode,sqsx.getFywflcode());
                queryWrapper.like(StringUtils.isNotBlank(sqsx.getFsxmc()),SpcySqsxBasic::getFsxmc,sqsx.getFsxmc());
                queryWrapper.like(StringUtils.isNotBlank(sqsx.getFqymc()),SpcySqsxBasic::getFqymc,sqsx.getFqymc());
                queryWrapper.like(StringUtils.isNotBlank(sqsx.getFszdq()),SpcySqsxBasic::getFsxmc,sqsx.getFszdq());
                queryWrapper.like(StringUtils.isNotBlank(sqsx.getFslbh()),SpcySqsxBasic::getFslbh,sqsx.getFslbh());
                queryWrapper.like(StringUtils.isNotBlank(sqsx.getFrckpjg()),SpcySqsxBasic::getFrckpjg,sqsx.getFrckpjg());

                if (StringUtils.isNotBlank(orderItemVo.getOrderItem())){
                    OrderItemUtils.setOrderItem(queryWrapper,orderItemVo);
                }
                List<SpcySqsxBasic> sqsxBasicList = spcySqsxBaiscService.list(queryWrapper);
                // 条件导出
                if (CollectionUtils.isNotEmpty(sqsxBasicList)){
                    for (SpcySqsxBasic e : sqsxBasicList){
                        list.add(e);
                    }
                }
            }
            myExcelUtils.outputListToExclFile(BusinessConstant.IMPORT_RCKP_TJ_XML,list,out); // 导出模板数据成excel
        } catch (Exception e) {
            log.error("导出日常考评基本信息数据出错-{}",e.getMessage());
        }
    }
}
